<?php
session_start();
include "./includes/config.php";
include './classes/Auth.class.php';
include "./includes/dogtagsimg1.php";
include "./includes/dogtagstitles.php";

$id = $_POST['id'];
$type = substr($id, 0, 3);

if($type == 'dtb')
{
	$dtb = substr($id, 3, 3);
	$dta = Battlelog\User::UserDTA();
}

if($type == 'dta')
{
	$dta = substr($id, 3, 3);
	$dtb = Battlelog\User::UserDTB();
}

$clantag = Battlelog\User::UserCLNTG();
$dsnm = Battlelog\User::UserDSNM();

echo "<aside class='span4 dogtag-aside sticky-scroll fixed' style='top: 275px; margin-left: 688px;'>";
echo "<div id='dogtags-equipped-box' class='box equipped'>";
if($type == 'dtb')
{
	echo "<div class='box-content selected-dog-tags basic-active'>\n";
}
else
{
	echo "<div class='box-content selected-dog-tags advanced-active'>\n";
}
echo "<div class='dogtags dogtags-chain horizontal' style='margin-left:7px'>\n";
drawimg("dtb"."$dtb");
drawimg("dta"."$dta");
echo "<div class='dog-tag-name-overlay'><p>".$dsnm."</p></div></div>";
echo "<button id='dogtags-equip' class='btn btn-small btn-primary btn-equip' onclick='savedogtags(); return false;'>".$lang['EquipDogTags']."</button>";
echo "</div>";

if($type == 'dtb')
	drawtitle("dtb"."$dtb", $lang);
else
	drawtitle("dta"."$dta", $lang);
echo "</div>";
echo "</aside>";

$dtaint = $dta;
$dtbint = $dtb;
$dta = str_pad(dechex($dta), 3 ,'0', STR_PAD_LEFT);
$dtb = str_pad(dechex($dtb), 3 ,'0', STR_PAD_LEFT);
$temptag =str_pad($clantag, 4 ,'0', STR_PAD_LEFT);
$tag = str_replace(' ','',ascii2hex(base64_decode(bf3Conv($temptag,1))));
					
$uatt=hexdec($dta.$dtb.$tag);

if($type == 'dtb')
{
	Battlelog\User::UpdateUserDTB($dtbint);
	$DBH = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
	$sth = $DBH->prepare('UPDATE players SET dtb="'.$dtbint.'", uatt="'.$uatt.'" WHERE dsnm="'.$dsnm.'"'); 
	$sth->execute();
}

if($type == 'dta')
{
	Battlelog\User::UpdateUserDTA($dtaint);
	$DBH = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
	$sth = $DBH->prepare('UPDATE players SET dta="'.$dtaint.'", uatt="'.$uatt.'" WHERE dsnm="'.$dsnm.'"'); 
	$sth->execute();
	
}
$DBH = null;
?>
